package com.example.auth.uitls;

import com.example.auth.model.UserModel;

/**
 * @Classname UserModelUtils
 * @Description TODO
 * @Date 2022/7/27 20:47
 * @Created by XiongXiong
 * @Author: X.I.O
 */
public class UserModelUtils {

    private static final ThreadLocal<UserModel> userThreadLocal = new ThreadLocal<>();

    public static void addCurrentUser(UserModel userModel) {

        //登录对象从这里获取然后set进ThreadLocal
        //具体根据业务逻辑来
        if(userModel!=null){
            userThreadLocal.set(userModel);
        }
    }

    public static UserModel getCurrentUser() {
        return userThreadLocal.get();
    }

    /**
     * 防止内存泄漏
     */
    public static void remove() {
        userThreadLocal.remove();
    }

}
